package com.kaifamiao.month03.day0317;

public class StackTest {


    public static void main(String[] args) {
        String str = "()()";
        System.out.println(isLegal(str));
    }

    public static boolean isLegal(String str){
        Stack stack = new Stack();
        for(int i = 0; i < str.length(); i ++){
            if('(' == str.charAt(i)){
                stack.push(str.charAt(i));
            }else if(str.charAt(i) == ')'){
                if(stack.isEmpty()) {
                    return false;
                }else{
                    stack.pop();
                }
            }
        }
        return stack.isEmpty();
    }
}
